package Test;

//树上上升序列
import java.util.*;
class TreeNode {
    int weight;
    List<TreeNode> friend;

    public TreeNode(int weight) {
        this.weight = weight;
        friend = new ArrayList<>();
    }
}

public class Main {
    public static void main2(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        long[] num = new long[a];
        for (int i = 0; i < a; i++) {
            num[i] = sc.nextLong();
        }
        long k = 0;
        Arrays.sort(num);
        while (num[a - 1] >= a) {
            //注意两点：1 long  2 避免超空 max/n
            long tmp = num[a-1]/a;
            num[a - 1] -= a*tmp;
            for (int i = 0; i < a - 1; i++) {
                num[i] += tmp;
            }
            Arrays.sort(num);
            k+=tmp;
        }
        System.out.println(k);

    }

    static int max = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        TreeNode[] nodes = new TreeNode[n];
        for (int i = 0; i < n; i++) {
            nodes[i] = new TreeNode(sc.nextInt());
        }
        for (int i = 0; i < n - 1; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            nodes[a].friend.add(nodes[b]);
            nodes[b].friend.add(nodes[a]);
        }

        for (TreeNode node : nodes) {
            dfs(node, 1);
        }
        System.out.println(max);
    }
    private static void dfs(TreeNode node, int preSum) {
        max = Math.max(max, preSum);
        for (TreeNode friend : node.friend) {
            if (friend.weight > node.weight) {
                dfs(friend, preSum + 1);
            }
        }
    }


}
